﻿<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<c:set var="basePath" value="${pageContext.request.contextPath}"/>
<!DOCTYPE HTML>
<html lang="zh-cn">
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>新增权限</title>
	<jsp:include page="/resources/inc/formHead.jsp" />
</head>
<body>
<form id="createForm" class="layui-form layui-form-pane" method="post">
	<div class="layui-form-item" >
		<label class="layui-form-label">类型</label>
		<div class="layui-input-block">
			<input type="radio" name="type" value="1" title="目录" lay-filter="typeFilter" <c:if test="${permission.type==1}">checked</c:if>>
			<input type="radio" name="type" value="2" title="菜单" lay-filter="typeFilter" <c:if test="${permission.type==2}">checked</c:if>>
			<input type="radio" name="type" value="3" title="按钮" lay-filter="typeFilter" <c:if test="${permission.type==3}">checked</c:if>>
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">选择系统</label>
		<div class="layui-input-inline type1 type2 type3">
			<select id="systemId" name="systemId" lay-verify="required" lay-filter="systemFilter">
				<option value="0">请选择系统</option>
				<c:forEach var="upmsSystem" items="${upmsSystems}">
					<option value="${upmsSystem.systemId}" <c:if test="${permission.systemId==upmsSystem.systemId}">selected="selected"</c:if>>${upmsSystem.title}</option>
				</c:forEach>
			</select>
		</div>
		<div class="layui-input-inline type2 type3">
			<select id="pid" name="pid">
				<option value="0">请选择上级</option>
			</select>
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label" for="name">名称</label>
		<div class="layui-input-block">
			<input id="name" type="text" class="layui-input" name="name" value="${permission.name}" lay-verify="required">
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label" for="permissionValue">权限值</label>
		<div class="layui-input-block">
			<input id="permissionValue" type="text" class="layui-input" name="permissionValue" value="${permission.permissionValue}">
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label" for="uri">路径</label>
		<div class="layui-input-block">
			<input id="uri" type="text" class="layui-input" name="uri" value="${permission.uri}">
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label" for="icon">图标</label>
		<div class="layui-input-block">
			<input id="icon" type="text" class="layui-input" name="icon" value="${permission.icon}">
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">状态</label>
		<div class="layui-input-block">
			<input type="radio" name="status" value="1" title="正常" <c:if test="${permission.status==1}">checked</c:if>>
			<input type="radio" name="status" value="0" title="锁定" <c:if test="${permission.status==0}">checked</c:if>>
		</div>
	</div>
	<div class="layui-form-item">
		<div class="layui-input-block">
			<button class="layui-btn" lay-submit="" lay-filter="sub">立即提交</button>
			<button type="reset" class="layui-btn layui-btn-primary">重置</button>
		</div>
	</div>
</form>
<jsp:include page="/resources/inc/formFooter.jsp" />
<script>
	$(function () {
		FormCommon.initForm({
			url: "${basePath}/manage/permission/update/${permission.permissionId}"
		});
		initType();
		initPid(${permission.pid});
	});

	var pidType = 0;
	var systemId = ${permission.systemId};
	var type = ${permission.type};

	layForm.on('radio(typeFilter)',function (data) {
		type = data.value;
		initType();
	});
	// 选择系统
	layForm.on('select(systemFilter)',function (data) {
		systemId = data.value;
		initType();
	});

	function initType() {
		// 显示对应必填项
		$('.type1,.type2,.type3').hide(0, function () {
			$('.type' + type).show();
		});
		// 级联菜单
		if (type == 2) {
			pidType = 1;
			initPid();
		}
		if (type == 3) {
			pidType = 2
			initPid();
		}
	}
	function initPid(val) {
		if (systemId != 0) {
			$.getJSON('${basePath}/manage/permission/list', {systemId: systemId, type: pidType, limit: 10000}, function(json) {
				$('#pid').empty();
				$('#pid').append("<option value='0'>请选择上级</option>");
				for (var i = 0; i < json.rows.length; i ++) {
					var val = json.rows[i].permissionId;
					var text = json.rows[i].name;
					var optionHtml = "<option value='"+val+"' >" + text + "</option>";
					$('#pid').append(optionHtml);
				}
				if (!!val) {
					$('#pid').val(val);
				}
				layForm.render('select');
			});
		} else {
			$('#pid').empty();
			$('#pid').append("<option value='0'>请选择上级</option>");
			layForm.render('select');
		}
	}
</script>
</body>
</html>